# -*- coding: utf-8 -*-
from django.http import HttpResponse
from .models import first,remark
import json

def show(request):
    list = first.objects.all() 
    response = {}
    t = 0                           # 给每个first提供编号
    print('==========================')
    for var in list:      
        t+=1
        print(var.message)
        # 提取对于每个first的评论
        rmk = {}
        list2 = remark.objects.filter(follow_id=str(var.id)) # == or =?
        t2 = 0
        for var2 in list2:
            t2+=1
            rmk[t2]={"id":var2.id,"message":var2.message,"time":str(var2.time)}
        #  
        response[t]={"id":var.id,"name":var.name,"message":var.message,"like_count":var.like_count,"time":str(var.time),"remark":rmk}
    return HttpResponse(json.dumps(response))    

